﻿@using BabyShop.WebSite.Models
@model IEnumerable<ProductType>

@{
    ViewBag.Title = "ProductType Management";
    ViewBag.IsFormIndex = true;
}
@section FooterScript{
    <script type="text/javascript">
        $(function () {
            var $tbProductType = $('#tbProductType');
            $tbProductType.jqGrid({
                url: '@Url.Action("ProductTypeList")',
                datatype: "json",
                mtype: 'post',
                colNames: ['KeyGuid', '类型名', '上级类型', '创建时间', '是否删除', '操作'],
                colModel: [
                        { name: 'KeyGuid', index: 'ProductTypeGuid', width: 90, jsonmap: "ProductTypeGuid",
                            editable: false, hidden: true
                        },
                        { name: '类型名', index: 'ProductTypeName', width: 90, jsonmap: "ProductTypeName", editable: true },
                        { name: '上级类型', index: 'ParentProductType.ProductTypeName', label: '无', width: 90, editable: false },
                        { name: '创建时间', index: 'CommonColumns.LastModified', formatter: 'date',
                            formatoptions: { newformat: 'Y/m/d' }, width: 80, align: 'center', editable: true
                        },
                        { name: '是否删除', index: 'CommonColumns.IsDelete', width: 80, align: 'center',
                            editable: true, edittype: 'checkbox', editoptions: { value: '是:否'}
                        },
                        { name: 'Edit', index: 'Edit', width: 150, editable: false, align: 'center',
                            search: false, sortable: false
                        }
                    ],
                rowNum: 10,
                rowList: [10, 20, 30],
                pager: '#pagerProductType',
                sortname: "CommonColumns.LastModified",
                viewrecords: true,
                hidegrid: false,
                rownumbers: true,
                sortorder: "desc",
                caption: '@ViewBag.Title',
                height: '100%',
                width: '100%',
                ondblClickRow: EditEntry
            });

            var iframeSize = $.bs.getContainerWidthAndHeight($.removePrefix($.sysRes.iframeName), false);
            $tbProductType.jqGrid('navGrid', '#pagerProductType', { add: false, edit: false, del: false })
                .navButtonAdd('#pagerProductType', {
                    caption: "编辑",
                    buttonicon: "ui-icon-add",
                    onClickButton: function () {
                        var id = $tbProductType.getGridParam("selrow");
                        if (id == null) {
                            alert("请选择行！");
                            return;
                        }
                        if (id == "newId") return;
                        $tbProductType.editRow(id);
                        $tbProductType.setCell(id, "Edit",
                    "<input id='Button1' type='button' value='提交' onclick='Update(\"" + id + "\")' /><input id='Button2' type='button' value='取消' onclick='Cancel(\"" + id + "\")' />");
                    }
                }).navButtonAdd('#pagerProductType', {
                    caption: "删除",
                    buttonicon: "ui-icon-del",
                    onClickButton: function () {
                        var id = $tbProductType.getGridParam("selrow");
                        if (id == null) {
                            alert("请选择行！");
                            return;
                        }
                        DeleteEntry(id);
                    }
                }).setGridWidth(iframeSize.width);

            $(".searchTable>tbody>tr>td:has(label)").addClass("evenTD");
        });

        //取消编辑状态
        function Cancel(id) {
            if (id == "newId")
                $("#tbProductType").delRowData("newId");
            else {
                $("#tbProductType").restoreRow(id);
                $("#tbProductType").setCell(id, "Edit", "&nbsp;");
            }
        }

        function EditEntry(id) {
            if (id == "newId")
                return;
            else {
                var keyGuid = $("#tbProductType").getCell(id, "KeyGuid");
                $.bs.showDialog({ url: '@Url.Action("Edit")?keyGuid=' + keyGuid, title: '修改类型' });
            }
        }

        function DeleteEntry(rowId) {
            if(rowId != 'newId') {
                var keyGuid = $('#tbProductType').getCell(rowId, 'KeyGuid');
                $.ajax({
                        url: '@Url.Action("Remove")',
                        type: 'post',
                        dataType: 'json',
                        data: { keyGuid: keyGuid },
                        success: function(result) {
                            if (result.ErrorCode == 0)
                                $.bs.showMsg('提示信息', result.ShowMsg);
                            else
                                $.bs.showErr('出错啦', result.ShowMsg);
                        }
                    });
            }
            return;
        }
    </script>
}
<style type="text/css">
    fieldset,.ui-jqgrid
    {
        width:95%;
        margin:0 auto 10px;
    }
    fieldset legend
    {
        margin-left: 30px;
    }
    .searchTable
    {
        width: 90%;
    }
    .searchTable td
    {
        width: 100px;
    }
    .searchTable td.evenTD
    {
        width: 50px;
        text-align:right;
    }
    .searchTable td label
    {
        display: inline-block;
        padding-right:5px;
    }
    .searchTable td label:after
    {
        content:":";
    }
</style>
<fieldset class="ui-corner-all">
    <legend>查询</legend>
    <table class="searchTable">
        <tr>
            <td><label for="txtProductType">产品类型名称</label></td>
            <td>
                <input type="text" id="txtProductType" autofocus="true"
                 placeholder="产品类型名称" 
                 data-searchField="ProductTypeName" data-searchOp="cn" />
            </td>
            <td><label for="txtProductType">菜单类型</label></td>
            <td>
                @Html.DropDownList("slMenuType",typeof(MenuType),"全部",
                new {
                    data_searchField = "MenuTypeInt",
                    data_searchOp = "eq"
                })
            </td>
            <td rowspan="2">
                <input type="button" id="btnSearch" class="ui-button ui-jqgrid-search" value="查询" />
                @Html.ActionLink("新建产品类型", "Create", null, new { id = "lkCreate", @class = "ui-button ui-jqgrid-create" })
            </td>
        </tr>
    </table>
</fieldset>
<table id="tbProductType" class="ui-jqgrid-btable"></table>
<nav id="pagerProductType" class="ui-jqgrid-pager"></nav>
